package com.bw.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

import com.bw.utils.DateUtils;

public class DateTest {
	//计算年龄的测试方法
    @Test
    public void testGetage() throws ParseException {
    	SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
    	String date="2002-03-01";
    	Date parse = sim.parse(date);
    	int age = DateUtils.getAge(parse);
    	System.out.println("年龄为："+age);
    }
    
  //计算月初的测试方法
    @Test
    public void testgetDateByMonthInit() throws ParseException {
    	SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String date="2019-09-19 19:29:39";
    	Date parse = sim.parse(date);
    	Date dateByMonthInit = DateUtils.getDateByMonthInit(parse);
    	System.out.println("月初时间为："+sim.format(dateByMonthInit));
    }
    
  //计算月末的测试方法
    @Test
    public void testgetDateByMonthLast() throws ParseException {
    	SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String date="2019-09-19 19:29:39";
    	Date parse = sim.parse(date);
    	Date dateByMonthInit = DateUtils.getDateByMonthLast(parse);
    	System.out.println("月末时间为："+sim.format(dateByMonthInit));
    }
    
  //计算未来日期离今天还剩的天数的测试方法
    @Test
    public void testgetDaysByFuture() throws ParseException {
    	SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String date="2021-09-19 19:29:39";
    	Date parse = sim.parse(date);
    	int daysByFuture = DateUtils.getDaysByFuture(parse);
    	System.out.println("天数："+daysByFuture);
    }
    //求过去日期离今天过去的天数的测试方法
    @Test
    public void testgetDaysByDeparted() throws ParseException {
    	SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String date="2019-09-19 19:29:39";
    	Date parse = sim.parse(date);
    	int daysByFuture = DateUtils.getDaysByDeparted(parse);
    	System.out.println("天数："+daysByFuture);
    }
    
}
